package mylist
{
	import com.ViewSet;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author db0@qq.com
	 */
	public class ShowBig extends Sprite
	{
		public static var main:ShowBig;
		private static var bg:Bitmap;
		private static var photoBmp:Bitmap;
		private static var rotContainer:RotatableScalable;
		private static var backBtn:Sprite = new Sprite();
		
		public function ShowBig()
		{
			if (main)
				return;
			main = this;
			
			[Embed(source="../asset/backbtn.png")]
			var backbtn:Class;
//if(!DragItem.willSend)
			backBtn.addChild(new backbtn());
			backBtn.addEventListener(MouseEvent.CLICK, hide);
			mouseChildren = true;
			addEventListener(Event.ADDED_TO_STAGE, init);
			//if(DragItem.willSend)addEventListener(MouseEvent.CLICK, hide);
		}
		
		private function init(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			logs.adds("++++++++++++");
			bg = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xff000000));
			main.addChild(bg);
			hide();
		}
		
		public function shows(item:Bitmap):void
		{
			item.smoothing = true;
			hide();
			logs.adds("show  big()", stage);
			visible = true;
			rotContainer = new RotatableScalable(stage);
			main.addChild(rotContainer);
			photoBmp = new Bitmap(item.bitmapData);
			if (stage)
			{
				ViewSet.fullCenter(photoBmp, 0, 0, stage.stageWidth, stage.stageHeight);
				rotContainer.addChild(photoBmp);
				if (!DragItem.willSend)
					PrintBtn.main.makePrintContainer(new Bitmap(photoBmp.bitmapData));
			}
			main.addChild(backBtn);
			backBtn.x = stage.stageWidth - backBtn.width * 2;
			backBtn.y = backBtn.height * .5;
		}
		
		public function hide(e:MouseEvent = null):void
		{
			visible = false;
			
			if (photoBmp)
			{
				if (rotContainer.contains(photoBmp))
					rotContainer.removeChild(photoBmp);
					//photoBmp.bitmapData.dispose();
			}
			if (rotContainer)
			{
				if (main.contains(rotContainer))
					removeChild(rotContainer);
				rotContainer = null;
			}
			photoBmp = null;
			if (PrintBtn.main)
				PrintBtn.main.hide();
		}
	
	}

}
